package com.example.qxfw.dataBaseManager.Controller;

import com.alibaba.excel.EasyExcel;
import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.JgInfo;
import com.example.qxfw.common.entity.RoadlineType;
import com.example.qxfw.common.entity.TrafficHightwayPnt;
import com.example.qxfw.common.entity.TravelPredict;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.common.entity.qx.TownshipStation;
import com.example.qxfw.common.entity.zy.EnviroStation;
import com.example.qxfw.common.entity.zy.TourStations;
import com.example.qxfw.common.entity.zy.TrafficWeatherSta;
import com.example.qxfw.common.listener.GenericDataListener;
import com.example.qxfw.common.service.EnviroStationServicePro;
import com.example.qxfw.common.util.EasyExcelUtil;
import com.example.qxfw.dataBaseManager.service.ProfessionalInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/8  星期六   15:47
 * @description : 此类用来 专业信息
 ***************************************/
@Slf4j
@Api(tags = "数据库管理-专业信息")
@RestController
@CrossOrigin
@RequestMapping("/ProfessionalInformationController")
public class ProfessionalInformationController {

    @Autowired
    private ProfessionalInformationService professionalInformationService;

    @Autowired
    private EnviroStationServicePro enviroStationServicePro;

    @ApiIgnore
    @ApiOperation("获取环保站")
    @RequestMapping(value = "getEnviroStationRtrim", method = RequestMethod.GET)
    public SysResult getEnviroStationRtrim() {
        List<EnviroStation> enviroStationRtrim = this.professionalInformationService.getEnviroStationRtrim();
        return SysResult.success(enviroStationRtrim);
    }

    @ApiIgnore
    @ApiOperation("添加环保站")
    @RequestMapping(value = "saveEnviroStation", method = RequestMethod.POST)
    public SysResult saveEnviroStation(@RequestBody EnviroStation envirostation) {
        List<EnviroStation> envirostations = this.professionalInformationService.judgeEnviroStation(envirostation.getStationname());
        if (envirostations.size() > 0) {
            return SysResult.fail("该站点已存在");
        } else {
            Integer integer = this.professionalInformationService.saveEnviroStation(envirostation);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("删除环保站")
    @RequestMapping(value = "deleteEnviroStation", method = RequestMethod.GET)
    public SysResult deleteEnviroStation(String stationName) {
        Integer integer = this.professionalInformationService.deleteEnviroStation(stationName);
        return SysResult.success(integer);
    }

    @ApiIgnore
    @ApiOperation("更新环保站")
    @RequestMapping(value = "updateEnviroStation", method = RequestMethod.POST)
    public SysResult updateEnviroStation(@RequestBody EnviroStation envirostation) {
        Integer integer = this.professionalInformationService.updateEnviroStation(envirostation);
        return SysResult.success(integer);
    }

    @ApiIgnore
    @ApiOperation("导入环保站信息")
    @PostMapping("/importEnviroStation")
    public String importEnviroStation(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), EnviroStation.class, new GenericDataListener(enviroStationServicePro)).sheet().doRead();
        return "success";
    }

    @ApiIgnore
    @ApiOperation("导出环保站信息")
    @RequestMapping(value = "exportEnviroStation", method = RequestMethod.POST)
    public void exportEnviroStation(HttpServletResponse response) throws IOException {
        List<EnviroStation> allnviroStation = this.professionalInformationService.getAllnviroStation();
        EasyExcelUtil.exportDataToExcel(response, "环保站", "数据", allnviroStation, EnviroStation.class);
    }

    @ApiIgnore
    @ApiOperation("获取道路类型")
    @RequestMapping(value = "getDistinctStationIdFromSmallScaleStation", method = RequestMethod.GET)
    public SysResult getDistinctStationIdFromSmallScaleStation() {
        List<SmallScaleStation> distinctStationId = this.professionalInformationService.getDistinctStationId();
        return SysResult.success(distinctStationId);
    }

    @ApiIgnore
    @ApiOperation("查询")
    @RequestMapping(value = "getDistinctStationIdByCityFromTownShipStation", method = RequestMethod.GET)
    public SysResult getDistinctStationIdByCityFromTownShipStation(String city) {
        List<TownshipStation> distinctStationIdByCityFromTownShipStation = this.professionalInformationService.getDistinctStationIdByCityFromTownShipStation(city);
        return SysResult.success(distinctStationIdByCityFromTownShipStation);
    }

    @ApiIgnore
    @ApiOperation("查询交通气象站的信息")
    @RequestMapping(value = "getTrafficHightwayPntOrderById", method = RequestMethod.GET)
    public SysResult getTrafficHightwayPntOrderById() {
        List<TrafficHightwayPnt> trafficHightwayPntOrderById = this.professionalInformationService.getTrafficHightwayPntOrderById();
        return SysResult.success(trafficHightwayPntOrderById);
    }

    @ApiIgnore
    @ApiOperation("根据城市和经纬度查询")
    @RequestMapping(value = "getTownShipStationByLongitude", method = RequestMethod.GET)
    public SysResult getTownShipStationByLongitude(String city, Double jd, Double wd) {
        List<TownshipStation> townShipStationByLongitude = this.professionalInformationService.getTownShipStationByLongitude(city, jd, wd);
        return SysResult.success(townShipStationByLongitude);
    }

    @ApiIgnore
    @ApiOperation("根据城市经纬度查询")
    @RequestMapping(value = "getSmallScaleStationByLongitude", method = RequestMethod.GET)
    public SysResult getSmallScaleStationByLongitude(String city, Double jd, Double wd) {
        List<SmallScaleStation> smallScaleStationByLongitude = this.professionalInformationService.getSmallScaleStationByLongitude(city, jd, wd);
        return SysResult.success(smallScaleStationByLongitude);
    }

    @ApiIgnore
    @ApiOperation("保存")
    @RequestMapping(value = "saveTrafficHighwayPnt", method = RequestMethod.POST)
    public SysResult saveTrafficHighwayPnt(TrafficHightwayPnt trafficHightwayPnt) {
        List<TrafficHightwayPnt> trafficHightWayPntById = this.professionalInformationService.getTrafficHightWayPntById(trafficHightwayPnt.getId());
        if (trafficHightWayPntById.size() > 0) {
            return SysResult.fail("已存在该站点");
        } else {
            Integer integer = this.professionalInformationService.saveTrafficHightWayPnt(trafficHightwayPnt);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("更新站点")
    @RequestMapping(value = "updateTrafficHighWayPnt", method = RequestMethod.POST)
    public SysResult updateTrafficHighWayPnt(TrafficHightwayPnt trafficHightwayPnt) {
        List<TrafficHightwayPnt> trafficHightWayPntById = this.professionalInformationService.getTrafficHightWayPntById(trafficHightwayPnt.getId());
        if (trafficHightWayPntById.size() > 0) {
            Integer integer = this.professionalInformationService.updateTrafficHightWayPnt(trafficHightwayPnt);
            return SysResult.success(integer);
        } else {
            return SysResult.fail("没有该站点，无法更新");
        }
    }

    @ApiIgnore
    @ApiOperation("删除")
    @RequestMapping(value = "deleteTrafficHightWayPnt", method = RequestMethod.GET)
    public SysResult deleteTrafficHightWayPnt(Integer id) {
        Integer integer = this.professionalInformationService.deleteTrafficHightWayPnt(id);
        return SysResult.success(integer);
    }

    @ApiIgnore
    @ApiOperation("查询所有公路")
    @RequestMapping(value = "getAllTrafficHightWayPnt", method = RequestMethod.GET)
    public SysResult getAllTrafficHightWayPnt(){
        List<TrafficHightwayPnt> allTrafficHightWayPnt = this.professionalInformationService.getAllTrafficHightWayPnt();
        return SysResult.success(allTrafficHightWayPnt);
    }

    @ApiIgnore
    @ApiOperation("根据Id查询排序")
    @RequestMapping(value = "getTrafficHightWayPntOrderById", method = RequestMethod.GET)
    public SysResult getTrafficHightWayPntOrderById() {
        List<TrafficHightwayPnt> trafficHightwayPntOrderById = this.professionalInformationService.getTrafficHeightWayPntOrderById();
        return SysResult.success(trafficHightwayPntOrderById);
    }

    @ApiIgnore
    @ApiOperation("查询道路类型")
    @RequestMapping(value = "getDistinctRoadTypeFromRoadLineType", method = RequestMethod.GET)
    public SysResult getDistinctRoadTypeFromRoadLineType() {
        List<RoadlineType> distinctRoadTypeFromRoadLineType = this.professionalInformationService.getDistinctRoadTypeFromRoadLineType();
        return SysResult.success(distinctRoadTypeFromRoadLineType);
    }


    @ApiIgnore
    @ApiOperation("根据道路类型查询")
    @RequestMapping(value = "getRoadLoneTypeByRoadType", method = RequestMethod.GET)
    public SysResult getRoadLoneTypeByRoadType(String roadType) {
        List<RoadlineType> roadLoneTypeByRoadType = this.professionalInformationService.getRoadLineTypeByRoadType(roadType);
        return SysResult.success(roadLoneTypeByRoadType);
    }

    @ApiIgnore
    @ApiOperation("保存道路类型")
    @RequestMapping(value = "saveRoadLineType", method = RequestMethod.POST)
    public SysResult saveRoadLineType(@RequestBody RoadlineType roadlineType) {
        List<RoadlineType> roadLineTypeByRoadType = this.professionalInformationService.getRoadLineTypeByRoadType(roadlineType.getRoadtype());
        if (roadLineTypeByRoadType.size() > 0) {
            return SysResult.success("此道路类型已存在");
        } else {
            Integer integer = this.professionalInformationService.saveRoadLineType(roadlineType);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("更新道路类型")
    @RequestMapping(value = "updateRoadLineType", method = RequestMethod.POST)
    public SysResult updateRoadLineType(@RequestBody RoadlineType roadlineType) {
        List<RoadlineType> roadLineTypeByRoadType = this.professionalInformationService.getRoadLineTypeByRoadType(roadlineType.getRoadtype());
        if (roadLineTypeByRoadType.size() > 0) {
            Integer integer = this.professionalInformationService.updateRoadLineType(roadlineType);
            return SysResult.success(integer);
        } else {
            return SysResult.success("不存在此道路");
        }
    }

    @ApiIgnore
    @ApiOperation("删除道路类型")
    @RequestMapping(value = "deleteRoadLineType", method = RequestMethod.GET)
    public SysResult deleteRoadLineType(String roadType) {
        List<RoadlineType> roadLineTypeByRoadType = this.professionalInformationService.getRoadLineTypeByRoadType(roadType);
        if (roadLineTypeByRoadType.size() > 0) {
            Integer integer = this.professionalInformationService.deleteRoadLineType(roadType);
            return SysResult.success(integer);
        } else {
            return SysResult.fail("无此道路，无法删除");
        }
    }

    @ApiIgnore
    @ApiOperation("根据景点名称查询景点")
    @RequestMapping(value = "getRtrimName", method = RequestMethod.GET)
    public SysResult getRtrimName(String name) {
        List<JgInfo> rtrimName = this.professionalInformationService.getRtrimNameFromJgInfo(name);
        return SysResult.success(rtrimName);
    }

    @ApiIgnore
    @ApiOperation("保存景点")
    @RequestMapping(value = "saveJgInfo", method = RequestMethod.POST)
    public SysResult saveJgInfo(@RequestBody JgInfo jgInfo) {
        List<JgInfo> rtrimName = this.professionalInformationService.getRtrimNameFromJgInfo(jgInfo.getName());
        if (rtrimName.size() > 0) {
            return SysResult.success("此景点已存在");
        } else {
            Integer integer = this.professionalInformationService.saveJgInfo(jgInfo);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("修改景点")
    @RequestMapping(value = "updateJgInfo", method = RequestMethod.POST)
    public SysResult updateJgInfo(@RequestBody JgInfo jgInfo) {
        List<JgInfo> rtrimNameFromJgInfo = this.professionalInformationService.getRtrimNameFromJgInfo(jgInfo.getName());
        if (rtrimNameFromJgInfo.size() > 0) {
            Integer integer = this.professionalInformationService.updateJgInfo(jgInfo);
            return SysResult.success(integer);
        } else {
            return SysResult.success("无此站点信息，无法修改");
        }
    }

    @ApiIgnore
    @ApiOperation("删除景点")
    @RequestMapping(value = "deleteJgInfo", method = RequestMethod.GET)
    public SysResult deleteJgInfo(String name) {
        List<JgInfo> rtrimNameFromJgInfo = this.professionalInformationService.getRtrimNameFromJgInfo(name);
        if (rtrimNameFromJgInfo.size() > 0) {
            Integer integer = this.professionalInformationService.deleteJgInfo(name);
            return SysResult.success(integer);
        } else {
            return SysResult.success("不存在此景点，无法删除");
        }
    }

    @ApiIgnore
    @ApiOperation("查询景点")
    @RequestMapping(value = "getTourStation", method = RequestMethod.GET)
    public SysResult getTourStation() {
        List<TourStations> tourStations = this.professionalInformationService.getTourStations();
        return SysResult.success(tourStations);
    }

    @ApiIgnore
    @ApiOperation("新增景点")
    @RequestMapping(value = "saveTourStation", method = RequestMethod.POST)
    public SysResult saveTourStation(@RequestBody TourStations tourStations) {
        List<TourStations> tourStationsByStationName = this.professionalInformationService.getTourStationsByStationName(tourStations.getStationname());
        if (tourStationsByStationName.size() > 0) {
            return SysResult.success("此景点已存在，无法添加");
        } else {
            Integer integer = this.professionalInformationService.saveTourStations(tourStations);
            return SysResult.success(integer);
        }
    }

    @ApiIgnore
    @ApiOperation("修改景点")
    @RequestMapping(value = "updateTourStation", method = RequestMethod.POST)
    public SysResult updateTourStation(@RequestBody TourStations tourStations) {
        List<TourStations> tourStationsByStationName = this.professionalInformationService.getTourStationsByStationName(tourStations.getStationname());
        if (tourStationsByStationName.size() > 0) {
            Integer integer = this.professionalInformationService.updateTourStations(tourStations);
            return SysResult.success(integer);
        } else {
            return SysResult.success("无此景点无法更新");
        }
    }

    @ApiIgnore
    @ApiOperation("删除")
    @RequestMapping(value = "deleteTourStation", method = RequestMethod.GET)
    public SysResult deleteTourStation(String stationName) {
        List<TourStations> tourStationsByStationName = this.professionalInformationService.getTourStationsByStationName(stationName);
        if (tourStationsByStationName.size() > 0) {
            Integer integer = this.professionalInformationService.deleteTourStations(stationName);
            return SysResult.success(integer);
        } else {
            return SysResult.success("不存在，无法删除");
        }
    }

    @ApiIgnore
    @ApiOperation("去重查询特色旅游指标")
    @RequestMapping(value = "selectDistinctJqNameFromTravelPredict", method = RequestMethod.GET)
    public SysResult selectDistinctJqNameFromTravelPredict() {
        List<TravelPredict> travelPredicts = this.professionalInformationService.selectDistinctJqNameFromTravelPredict();
        return SysResult.success(travelPredicts);
    }

    @ApiIgnore
    @ApiOperation("去重查询特色旅游指标")
    @RequestMapping(value = "selectDistinctSpotNameFromTravelPredict", method = RequestMethod.GET)
    public SysResult selectDistinctSpotNameFromTravelPredict() {
        List<TravelPredict> travelPredicts = this.professionalInformationService.selectDistinctSpotNameFromTravelPredict();
        return SysResult.success(travelPredicts);
    }

    @ApiIgnore
    @ApiOperation("查询所有特色旅游指标")
    @RequestMapping(value = "getAllTravelPredict", method = RequestMethod.GET)
    public SysResult getAllTravelPredict() {
        List<TravelPredict> allTravelPredict = this.professionalInformationService.getAllTravelPredict();
        return SysResult.success(allTravelPredict);
    }

    @ApiIgnore
    @ApiOperation("根据jqName和spotName模糊查询")
    @RequestMapping(value = "queryTravelPredictLikeJqNameAndSpotName", method = RequestMethod.GET)
    public SysResult queryTravelPredictLikeJqNameAndSpotName(String jqName, String spotName) {
        List<TravelPredict> travelPredicts = this.professionalInformationService.queryTravelPredictLikeJqNameAndSpotName(jqName, spotName);
        return SysResult.success(travelPredicts);
    }

    @ApiIgnore
    @ApiOperation("根据jqName和spotName查询")
    @RequestMapping(value = "selectTravelPredictByJqnNameAndSpotName", method = RequestMethod.GET)
    public SysResult selectTravelPredictByJqnNameAndSpotName(String jqName, String spotName) {
        List<TravelPredict> travelPredicts = this.professionalInformationService.selectTravelPredictByJqnNameAndSpotName(jqName, spotName);
        return SysResult.success(travelPredicts);
    }

    @ApiIgnore
    @ApiOperation("清空表")
    @RequestMapping(value = "clearTravelPredict", method = RequestMethod.GET)
    public SysResult clearTravelPredict() {
        Integer integer = this.professionalInformationService.clearTravelPredict();
        return SysResult.success(integer);
    }

    @ApiOperation("交通站管理-根据交通气象站站点排序")
    @RequestMapping(value = "getTrafficWeatherStaOrderByStationId", method = RequestMethod.GET)
    public SysResult getTrafficWeatherStaOrderByStationId() {
        List<TrafficWeatherSta> trafficWeatherStaOrderByStationId = this.professionalInformationService.getTrafficWeatherStaOrderByStationId();
        return SysResult.success(trafficWeatherStaOrderByStationId);
    }

    @ApiOperation("交通站管理-新增交通气象站")
    @RequestMapping(value = "saveTrafficWeatherSta", method = RequestMethod.POST)
    public SysResult saveTrafficWeatherSta(@RequestBody TrafficWeatherSta trafficWeatherSta) {
        List<TrafficWeatherSta> trafficWeatherStaByStationId = this.professionalInformationService.getTrafficWeatherStaByStationId(trafficWeatherSta.getStationid());
        if (trafficWeatherStaByStationId.size() > 0) {
            return SysResult.success("该交通气象站已存在");
        } else {
            Integer integer = this.professionalInformationService.saveTrafficWeatherSta(trafficWeatherSta);
            return SysResult.success(integer);
        }
    }

    @ApiOperation("交通站管理-更新气象交通站")
    @RequestMapping(value = "updateTrafficWeatherSta",method = RequestMethod.POST)
    public SysResult updateTrafficWeatherSta(@RequestBody TrafficWeatherSta trafficWeatherSta) {
        List<TrafficWeatherSta> trafficWeatherStaByStationId = this.professionalInformationService.getTrafficWeatherStaByStationId(trafficWeatherSta.getStationid());
        if (trafficWeatherStaByStationId.size()>0){
            Integer integer = this.professionalInformationService.updateTrafficWeatherSta(trafficWeatherSta);
            return SysResult.success(integer);
        }else {
            return SysResult.success("无此站点无法更新");
        }
    }

    @ApiOperation("交通站管理-删除气象站点")
    @RequestMapping(value = "deleteTrafficWeatherSta",method = RequestMethod.GET)
    public SysResult deleteTrafficWeatherSta(String stationId){
        Integer integer = this.professionalInformationService.deleteTrafficWeatherSta(stationId);
        return SysResult.success(integer);
    }

    @ApiOperation("交通站管理-查询所有气象站点")
    @RequestMapping(value = "getAllTrafficWeatherSta",method = RequestMethod.GET)
    public SysResult getAllTrafficWeatherSta(){
        List<TrafficWeatherSta> allTrafficWeatherSta = this.professionalInformationService.getAllTrafficWeatherSta();
        return SysResult.success(allTrafficWeatherSta);
    }

    @ApiOperation("交通站管理-根据stationid查询气象站点")
    @RequestMapping(value = "getTrafficWeatherStaById",method = RequestMethod.GET)
    public SysResult getTrafficWeatherStaById(String stationId){
        List<TrafficWeatherSta>  trafficWeatherStaByStationId  = this.professionalInformationService.getTrafficWeatherStaByStationId(stationId);
        return SysResult.success(trafficWeatherStaByStationId);
    }


}
